﻿using System.IO;

namespace Utils.FileFolderModule
{
    public class FolderHandler
    {
        public static bool CreateFolder(string folderPath)
        {
            if (Directory.Exists(folderPath))
            {
                return false;
            }

            Directory.CreateDirectory(folderPath);
            return Directory.Exists(folderPath);
        }

        public static bool GenerateFolder(string folderPath)
        {
            string[] ss = folderPath.Split('/', '\\');
            string directoryPath = ss[0];
            for (int i = 1; i < ss.Length; ++i)
            {
                directoryPath += "/" + ss[i];
                if (Directory.Exists(directoryPath))    
                {
                    continue;
                }

                Directory.CreateDirectory(directoryPath);
            }
            
            return Directory.Exists(folderPath);
        }
        
        public static bool DeleteEmptyFolder(string folderPath)
        {
            if (Directory.Exists(folderPath))
            {
                Directory.Delete(folderPath);
            }

            return !Directory.Exists(folderPath);
        }

        public static bool DeleteFolder(string folderPath, bool mode)
        {
            if (Directory.Exists(folderPath))
            {
                Directory.Delete(folderPath, mode);
                if (!mode)
                {
                    return false;
                }
            }

            return !Directory.Exists(folderPath);
        }
    }
}